package com.polaris.live.ui.live.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.polaris.live.common.ext.setOnSingleClickListener
import com.polaris.live.databinding.WidgetCallMaskBinding
import com.polaris.live.im.sfs.bean.live.SendLiveMessage
import com.polaris.live.im.sfs.bean.live.payload.CallMaskPayloadBean
import com.polaris.live.ui.live.widget.listener.OnMaskReportListener

/**
 * 遮罩
 *
 * @author Created by 半仙 on 2023/11/17/017 15:29
 */
class CallMaskView(context: Context, attrs: AttributeSet?) : LinearLayout(context, attrs) {

    private val mBinding = WidgetCallMaskBinding.inflate(LayoutInflater.from(context), this, true)

    protected var mOnMaskReportListener: OnMaskReportListener? = null

    init {
        visibility = GONE
    }

    fun maskState(sendLiveMessage: SendLiveMessage) {
        val payload = sendLiveMessage.payload as CallMaskPayloadBean
        if (payload.open) {
            visibility = VISIBLE
        } else {
            visibility = GONE
        }

        mBinding.tvOpen.text = payload.mastButton
        mBinding.tvReport.text = payload.reportButton
        mBinding.tvDetail.text = sendLiveMessage.content

        mBinding.tvOpen.setOnSingleClickListener {
            visibility = GONE
        }
        mBinding.tvReport.setOnSingleClickListener {
            mOnMaskReportListener?.onMaskReportListener()
        }
    }

    fun setOnMaskReportListener(l: OnMaskReportListener) {
        this.mOnMaskReportListener = l
    }

}